#!/usr/bin/env jq
# compile-config-0.52-input_loaders -- Adds default data loading processes for base relations
#
# - a deepdive-load extractor for relations declared in schema but lacking an extractor that outputs it
##
.deepdive_ as $deepdive

# add initialization processes that loads data into base relations declared in schema
| .deepdive_.execution.processes += (
    # first a handy map from relation to any process that outputs it
    ( $deepdive.extraction.extractors
    | with_entries({ key: (.value.output_relation // empty), value: .key })
    ) as $process_defining_the_relation |
    [ $deepdive.schema.relations // {} | to_entries[]
    | select($process_defining_the_relation[.key] | not)
    | { key: "\($deepdive.execution.process_init_relation_prefix)\(.key)"
      , value: { style: "cmd_extractor"
               , cmd: "deepdive create table \(.key | @sh) && deepdive load \(.key | @sh)"
               , dependencies_: [ $deepdive.execution.process_init_app ]
               , output_relation: .key
               , output_: ["data/\(.key)"]
               } }
    ] | from_entries )
